package org.example.controller;


import org.example.bean.Ptype;
import org.example.service.Impl.PtypeServise;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class PtypeController {
    @Autowired
    PtypeServise ptypeServise;
    @RequestMapping("/Plist.do")
    @ResponseBody   //1、修饰当前方法返回类型为JSON
    public List<Ptype> getAll(){  //2、将需要转换成json格式的对象直接返回
        List<Ptype> list =  ptypeServise.getAll();
        System.out.println("打印Ptype表");
        return list;
    }
    @RequestMapping("/delete4.do")
    public void delete(int id){
        ptypeServise.del(id);
    }
    @RequestMapping("/test4.do")
    public String add(@RequestParam("name") String name){
        Ptype ptype=new Ptype();
        ptype.setName(name);
        ptypeServise.add(ptype);
        return "产品详情";
    }
    @RequestMapping("/update5.do")
    public String update(@RequestParam("id")int id,@RequestParam("name") String name){
        Ptype ptype=new Ptype();
        ptype.setName(name);
        ptype.setId(id);
        ptypeServise.update(ptype);
        return"产品详情";
    }
}
